/**
 * 添加跟部门方法
 * @author     xiaogq
 */
function addRootDeptNode(){
    //得到组织版本号
    var version = $("#org_version").val();
    $.ajax({
        url : getRootPath()+"/"+Constants.initAddDeptUrl+"?version="+version,
        type :'POST',
        success:function(results){
            var obj = {"title":"组织信息添加","butName":"保存","formId":"organ_form","butFun":"saveDeptInfo","url":getRootPath()+"/Dept/saveAddDept.do","tId":""};
            parent.openAddOrganModal(results,obj);
        },
        error : function(){
            alert("获取部门(组织)信息失败!");
        }
    });
}

/**
 * 调整员工
 * @author     xiaogq
 * @param node
 */
function moveEmployeeToDept(node){
    //得到组织版本号
    var version = $("#org_version").val();
    var items = $('#bootstrapTable').bootstrapTable('getSelections');
    var empIds = "";
    if(items.length > 0){
        for(var i = 0; i < items.length; i++){
            empIds += ","+items[i].id;
        }
        empIds = empIds.substring(1);
        if(empIds != ""){
            $.ajax({
                url : getRootPath()+"/"+Constants.initMoveEmpToDeptUrl+"?empIds="+empIds+"&version="+version,
                type :'POST',
                success:function(results){
                    var obj = {"title":"调整员工","butName":"确认","formId":"move_emp_form","butFun":"saveMoveEmpToDept"};
                    parent.openModalMoveEmp(results,obj);
                },
                error : function(){
                    alert("获取移入员工信息失败!");
                }
            });
        }
    }else{
        alert("请选择需要调整的员工!");
    }
}

/**
 * 移入员工保存方法
 * @author     xiaogq
 * @param      node     form表单对象
 * @param      tId      树对象tId
 */
window.parent.saveMoveEmpToDept = function (node,version) {
    //获取组织值
    var deptId = $(node).find("select[name='pk_t_2_1']").val();
    var deptRank = $(node).find("select[name='pk_t_2_1'] option:selected").attr("deptRank");
    var postNodes = $(node).find("select[name='pk_t_4_1']");
    if(deptId == null || deptId == ""){
        alert("组织不能为空!");
        return;
    }
    if(postNodes.val() == null || postNodes.val() == ""){
        alert("该组织下没有岗位信息,请先添加岗位信息!");
        return;
    }
    var jsonStr = "";
    $(postNodes).each(function(){
        var empId =  $(this).attr("empId");
        var empName = $(this).attr("empName");
        jsonStr += ",{empId:'"+empId+"',empName:'"+empName+"',postId:'"+$(this).val()+"',postName:'"+$(this).find("option:selected").text()+"'}";
    });
    if(jsonStr != ""){
        jsonStr = "["+jsonStr.substring(1)+"]";
        $.ajax({
            url : getRootPath()+"/"+Constants.saveMoveEmpToDeptUrl+"?deptId="+deptId+"&deptRank="+deptRank+"&jsonStr="+jsonStr+"&version="+version,
            type :'POST',
            success:function(msg){
                var flag = msg.flag;
                if(flag){
                    parent.closeAddModal();
                    parent.refulshIframe();
                }else{
                    alert("移入员工失败!");
                }
            },
            error : function(){
                alert("移入员工异常!");
            }
        });
    }
}